<template>
	<el-container>
		<el-header class='x-header'>
			<b class="title">{{ page_info.title }}</b>
			<el-button v-if="$route.query.callback_url" size="mini" icon="el-icon-back" @click="g_page.funcBack">
				返回
			</el-button>
			<ExprotExcel api_url="/xadmin/prize/prize__item__list/export" :api_data="form_q"></ExprotExcel>
			<!--			<el-button size="mini" type="primary" icon="el-icon-edit" @click="g_page.funcRedirectEdit(`mall__freight__edit`)">-->
			<!--				退款确认-->
			<!--			</el-button>-->
			<el-button size="mini" icon="el-icon-refresh" @click="g_page.funcReload()">刷新</el-button>
		</el-header>
		<el-main class='x-main'>
			<el-form :inline="true" :model="form_q" size="mini">
				<el-form-item label="订单号">
					<el-input v-model="form_q.compOrderID" placeholder="订单号"></el-input>
				</el-form-item>
				<el-form-item label="手机号">
					<el-input v-model="form_q.compPhone" placeholder="手机号"></el-input>
				</el-form-item>
				<el-form-item label="审核状态">
					<el-select filterable clearable v-model="form_q.compState" placeholder="请选择">
						<el-option v-for="(item,index) in page_info.refo_apply_status" :label="item" :key="index" :value="index"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="g_page.funcSearch">搜索</el-button>
				</el-form-item>
			</el-form>
			<div class="table-wrap">
				<el-table stripe ref="multipleTable" tooltip-effect="dark"
						  @selection-change="g_page.funcTableSelectionChange"
						  :data="list_data">
					<el-table-column type="selection"></el-table-column>
					<el-table-column label="订单号">
						<template slot-scope="data">
							<div v-html="data.row.refo_order_id"></div>
						</template>
					</el-table-column>
					<el-table-column label="购买用户">
						<template slot-scope="data">
							<div>{{ data.row.winfo_name }}</div>
							<div style="color: blue;">{{ data.row.winfo_phone }}</div>
							<div>{{ data.row.order_wxuser_id }}</div>
						</template>
					</el-table-column>
					<el-table-column label="商品">
						<template slot-scope="data">
							<div>{{ data.row.spu_name }}</div>
							<div>{{ data.row.spu_id }}</div>
						</template>
					</el-table-column>
					<el-table-column label="支付类型">
						<template slot-scope="data">
							{{data.row.type}}
						</template>
					</el-table-column>
					<el-table-column label="退款金额">
						<template slot-scope="data">
							{{ data.row.refo_refund_price }}
						</template>
					</el-table-column>
					<el-table-column label="退款原因">
						<template slot-scope="data">
							<el-input type="textarea" v-model="data.row.refo_apply_desc"></el-input>
						</template>
					</el-table-column>
					<el-table-column label="审核状态">
						<template slot-scope="data">
							<div>{{ data.row.apply_status }}</div>
						</template>
					</el-table-column>
					<el-table-column label="申请时间">
						<template slot-scope="data">
							{{ data.row.refo_create_date }}
						</template>
					</el-table-column>
					<el-table-column label="退款信息">
						<template slot-scope="data">
							<div v-if="data.row.refo_apply_status==1">
								<div v-if="data.row.refo_refund_errcode==0">待处理</div>
								<div style="font-size: 12px;" v-else>
									<div>已处理</div>
									<div>errmsg：{{data.row.refo_refund_errmsg}}</div>
									<div>{{data.row.refo_refund_date}}</div>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作">
						<template slot-scope="data">
							<div v-if="data.row.refo_apply_status==0">
								<el-button type="text" size="mini" @click="funcRefund(data.row.id,1)">
									同意退款
								</el-button>
								<el-button type="text" size="mini" @click="funcRefund(data.row.id,10)">
									不同意退款
								</el-button>
							</div>
							<div v-else>
								<el-button v-if="data.row.refo_apply_status==1 && data.row.refo_refund_errcode!=1" type="text" size="mini" @click="funcRefundAgent(data.row.id)">
									重新操作
								</el-button>
							</div>
						</template>
					</el-table-column>
				</el-table>
				<a target="_blank"></a>
			</div>
		</el-main>
		<!---->
		<!---->
		<!-- 分页 -->
		<el-footer v-if="page_show" class="x-page">
			<el-pagination class="paging" background layout="total, sizes, prev, pager, next, jumper"
						   @current-change="g_page.funcPageChange" :page-sizes="[page_size]"
						   :current-page="page_index" :page-size="page_size" :total="page_total">
			</el-pagination>
		</el-footer>
		<!---->
		<!---->
		<!-- 弹框 -->
		<el-dialog :title="form.app_idx+'配置'" :visible.sync="form_dialog_visible" width="70%">
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-form-item label="入口链接" v-if="!g_page.funcIsAdminAdd()">
					<el-input :disabled="true" v-model="form.oauth_url"/>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="g_page.funcBack" size="mini">取消</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
			</div>
		</el-dialog>
		<!---->
		<!---->
		<!---->
	</el-container>
</template>


<script>
	import ExprotExcel from '@/components/ExprotExcel'

	export default {
		components: {
			ExprotExcel
		},
		data() {
			let page_data = { super_uid: '' }
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			//
			return page_data
		},
		mounted() {
			console.log('mounted')
			//
			this.g_page.funcSetVue(this)
			// 应用ID
			this.g_page.funcSetApiUrlList('/xadmin/mall/mall__refund_item__list')
			// this.g_page.funcSetApiUrlDel('/xadmin/mall/mall__order_item__list/del')
			//页码
			this.g_page.funcSetPageSize(20)
			//搜索
			this.form_q = {
				'compKw': ''
			}
			this.g_page.funcGetList()
			//
			this.form_rules = {
				acc_uidX: [
					{
						required: true,
						message: '必填',
						trigger: 'blur'
					}
				]
			}
			//
		},
		methods: {
			////////////////////
			//退款审核
			funcRefund(id, apply) {
				let errmsg = '同意，确定吗？'
				if (apply != 1) {
					errmsg = '不同意，确定吗？'
				}
				this.g_cc.func_confirm(errmsg, () => {
					this.funcRefundApi(id, apply)
				})
			},
			////////////////////
			//退款api
			funcRefundApi(id, apply) {
				this.g_cc.func_axios({
					url: '/xadmin/mall/mall__refund_item__list/funcRefund',
					data: {
						id, id,
						apply: apply
					},
					success: (res) => {
						//
						if (res.data.errcode == 0) {
							this.g_cc.func_alert('成功', 'success', () => {
								this.g_page.funcGetList()
							})
						} else {
							this.g_cc.func_alert(res.data.errmsg)
						}
					}
					//
				})
			},
			////////////////////
			//退款api
			funcRefundAgent(id) {
				this.g_cc.func_axios({
					url: '/xadmin/mall/mall__refund_item__list/funcRefundAgent',
					data: {
						id, id,
					},
					success: (res) => {
						//
						if (res.data.errcode == 0) {
							this.g_cc.func_alert('成功', 'success', () => {
								this.g_page.funcGetList()
							})
						} else {
							this.g_cc.func_alert(res.data.errmsg)
						}
					}
					//
				})
			}
			////////////////////
		}
	}
</script>

